package com.longdaji.decoration.ui.wear;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.longdaji.decoration.R;
import com.longdaji.decoration.data.bean.CaptainInfoBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by longtao on 2018/1/31.
 */

public class CaptainInfoAdapter extends RecyclerView.Adapter<CaptainInfoAdapter.ViewHolder> {
    private Context mContext;
    private List<CaptainInfoBean> mCaptainList;

    public CaptainInfoAdapter(Context context, List<CaptainInfoBean> captainList) {
        if (captainList == null)
            captainList = new ArrayList<>();
        this.mCaptainList = captainList;
        this.mContext = context;
    }

    public void setData(List<CaptainInfoBean> captainList) {
        if (captainList == null)
            captainList = new ArrayList<>();
        this.mCaptainList = captainList;
        notifyDataSetChanged();
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_captain_info, parent, false);
        ViewHolder holder = new ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {
        final CaptainInfoBean captainInfo = mCaptainList.get(position);
        if (captainInfo == null) {
            return;
        }
        if (captainInfo.getUserName() != null) {
            holder.name.setText(captainInfo.getName());
        }
        if (captainInfo.getTelephone() != null) {
            holder.phone.setText(captainInfo.getTelephone());
        }
        holder.addr.setText(captainInfo.getCampusName() + captainInfo.getDormitoryName());
    }


    @Override
    public int getItemCount() {
        return mCaptainList.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {

        TextView name;
        TextView phone;
        TextView addr;
        TextView copy;


        public ViewHolder(View itemView) {
            super(itemView);
            name = itemView.findViewById(R.id.tv_name);
            phone = itemView.findViewById(R.id.tv_phone);
            addr = itemView.findViewById(R.id.tv_addr);
            copy = itemView.findViewById(R.id.tv_copy);
        }
    }

}
